/*
 * @Author: lijing
 * @e-mail: 1413979079@qq.com
 * @LastEditors: lijing
 * @Date: 2020-05-03 10:07:54
 * @LastEditTime: 2020-06-25 22:52:06
 * @FilePath: \client\src\model\ImageCard.ts
 * @Description: image
 */
import UserInfo from "./UserInfo";
import Comment from "./Comment";

export default class ImageCard {
  public id: number;
  public createdAt: string;
  public title: string;
  public desc: string;
  public url: string;
  public label: string[] = [];
  public likes: number;
  public comments: Comment[] = [];
  public userInfo: UserInfo = new UserInfo();
  public collectors: number[] = [];
  public static create(image: any): ImageCard {
    const res = new ImageCard();
    res.id = image.id;
    res.createdAt = image.created_at;
    res.title = image.title;
    res.desc = image.desc;
    res.url = image.url;
    res.label = image.label.split(",");
    res.likes = image.likes;
    res.comments = [];
    res.collectors = image.collectors;
    if (image.comments) {
      image.comments.forEach((ele: any) => {
        res.comments.push(Comment.create(ele));
      });
    }
    res.userInfo = UserInfo.create(image.user_info);
    return res;
  }
}
